package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.EmployeeLeaveRegister;
import com.amsp.oa.oademo.mapper.EmployeeLeaveRegisterMapper;
import com.amsp.oa.oademo.service.EmployeeLeaveRegisterService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class EmployeeLeaveRegisterServiceImpl extends ServiceImpl<EmployeeLeaveRegisterMapper, EmployeeLeaveRegister>
        implements EmployeeLeaveRegisterService {

    @Override
    public IPage<EmployeeLeaveRegister> getPage(Integer current, Integer size, String deptName, String teamGroup) {
        LambdaQueryWrapper<EmployeeLeaveRegister> wrapper = new LambdaQueryWrapper<>();

        if (StringUtils.hasText(deptName)) {
            wrapper.like(EmployeeLeaveRegister::getDeptName, deptName);
        }
        if (StringUtils.hasText(teamGroup)) {
            wrapper.like(EmployeeLeaveRegister::getTeamGroup, teamGroup);
        }

        wrapper.orderByDesc(EmployeeLeaveRegister::getCreateTime);

        return page(new Page<>(current, size), wrapper);
    }
}